// Fill out your copyright notice in the Description page of Project Settings.

#include "Configs.h"
#include "Engine/Texture2D.h"
#include "BmpRead.h"

// Sets default values
AConfigs::AConfigs() 
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;
	MaxNum = 5000;
	intervel_X = 500;
	intervel_Y = 500;
	Length_X = 5000;
	Width_Y = 5000;
	IsLike = true;
	Inited = false;
	offset = 0;
	Inited = false;
}

// Called when the game starts or when spawned
void AConfigs::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AConfigs::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

void AConfigs::Init_Load(int load_key)
{
	IsReadMap = false;
	const int width=2;
	Init_location = this->GetActorLocation();	
	TArray<int> raw;
	raw.Init(0, Init_X);
	Load_Map.Init(raw, Init_Y);
	for (int i = 0; i < 30; i++) {
		for (int y = 0; y < Init_Y; y++) {
			if (i % 3 != 0) {
				for (int x = Init_X / 30 * (i + 1) - width; (x <= Init_X / 30 * (i + 1) +width)&&x<Init_X; x++) {
					Load_Map[y][x] = load_key;
				}
			}
			else
			{
				for (int x = Init_X / 30 * (i + 1) - 3 * width; (x <= Init_X / 30 * (i + 1) +3*width)&&x<Init_X; x++) {
					Load_Map[y][x] = load_key;
				}
			}
		}
	}
	//Main load;
	for (int y = 0; y < Init_Y; y++) {
		for (int x = Init_X / 2 - 6; (x < Init_X / 2 + 6)&&x<Init_X; x++) {
			Load_Map[y][x] = load_key;
		}
	}

	for (int x = 0; x < Init_X; x++) {
		for (int y = Init_Y / 2 - 6; (y < Init_Y / 2 + 6)&&y<Init_Y; y++) {
			Load_Map[y][x] = load_key;
		}
	}

	for (int i = 0; i < 30; i++) {
		for (int x = 0; x < Init_X; x++) {
			if (i % 3 != 0) {
				for (int y = Init_Y / 30 * (i + 1) - width; (y <= Init_Y / 30 * (i + 1) + width) && y<Init_Y; y++) {
					Load_Map[y][x] = load_key;
				}
			}
			else
			{
				for (int y = Init_Y / 30 * (i + 1) - 3* width; (y <= Init_Y / 30 * (i + 1) + 3* width) && y<Init_Y; y++) {
					Load_Map[y][x] = load_key;
				}
			}
		}
	}
	Inited = true;
}

void AConfigs::Init_Load(BmpRead br)
{
	IsReadMap = false;
	Init_location = this->GetActorLocation();
	TArray<int> raw;
	raw.Init(0, br.bmpWidth);
	Load_Map.Init(raw, br.bmpHeight);
	for (int y = br.bmpHeight-1; y >=0; y--) {
		for (int x = br.bmpWidth - 1; y >= 0; y--) {
			Load_Img[y][x] = br.ImageBits[y][x].R / 10;
		}
	}
}

